﻿using Hotel.BLL;
using Hotel.Model.Store;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StoreController : ControllerBase
    {

        StoreBLL bll;
        public StoreController(StoreBLL bll)
        {
            this.bll = bll;
        }
        /// <summary>
        /// 增加门店
        /// </summary>
        /// <param name="info">门店的实体类</param>
        /// <returns>返回影响的行数</returns>
        [HttpPost]
        public IActionResult PostAddStore(T_Store info)
        {
            try
            {
              
                int r = bll.PostAddStore(info);
                return Ok(new { 
                    data = r
                });
               
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取门店列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStoreList()
        {
            try
            {
                List<T_Store> list = bll.GetStoreList();
                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 删除门店
        /// </summary>
        /// <param name="id">门店的id</param>
        /// <returns>返回影响的行数</returns>
        [HttpGet]
        public IActionResult GetDelStoreItem(int id)
        {
            try
            {
                int res = bll.GetDelStoreItem(id);
                return Ok(new
                {
                    data = res
                });
              

            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取所有门店的销售信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStoreCountList(int? id = null)
        {
            try
            {
                var list = bll.GetStoreCountList(id);

                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
